package com.cy.pj.common.advisor;

import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

//定义切入点方法
//定义切入点方法执行时要植入的通知（扩展逻辑）
@Component
public class LogAdvisor extends StaticMethodMatcherPointcutAdvisor {

    public LogAdvisor(){
        setAdvice(new LogAdvice());
    }
    @Override
    public boolean matches(Method method, Class<?> aClass) {
        //true为切入点方法，false为非切入点方法
        try {
            Method targetMethod = aClass.getMethod(method.getName(), method.getParameterTypes());
            return targetMethod.getName().equals("sendsMsg");
        } catch (NoSuchMethodException e) {
            return false;
        }

    }
}
